#[derive(Serialize)]
pub struct Pagination<T> {
    pub total: i64,
    pub page_index: i64,
    pub page_size: i64,
    pub page_count: i64,
    pub rows: Vec<T>,
}

pub trait PaginationForm {
    fn get_page_index(&self) -> i64;
    fn get_page_size(&self) -> i64;

    fn get_offset(&self) -> i64 {
        (self.get_page_index() -1) * self.get_page_size()
    }
}

impl<T> Pagination<T> {
    pub fn empty() -> Self {
        Self {
            total: 0,
            page_index: 0,
            page_size: 0,
            page_count: 0,
            rows: vec![],
        }
    }
}

/// calculate pageCount
pub fn calc_page_count(total: i64, page_size: i64) -> i64 {
    if page_size == 0 {
        return 1;
    }
    (total + page_size - 1)/page_size
}